package com.web.zsqqimengzhixing.controller;

import com.web.zsqqimengzhixing.pojo.Articles;
import com.web.zsqqimengzhixing.pojo.Comments;
import com.web.zsqqimengzhixing.pojo.Result;
import com.web.zsqqimengzhixing.pojo.Upvotes;
import com.web.zsqqimengzhixing.service.ArticlesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/articles")
public class ArticlesController {
    @Autowired
    private ArticlesService articlesService;

    /**
     * 查询社区交流板块全部文章
     * @return
     */
    @GetMapping
    public Result select(){
        log.info("正在查询社区交流板块全部文章");
        List<Articles> articles = articlesService.select();
        return Result.success(articles);
    }

    /**
     * 添加文章
     * @param
     * @return
     */
    @PostMapping
    public Result addart(@RequestBody Articles articles){
        log.info("添加文章，内容为：{}",articles);
        articlesService.addart(articles);
        return Result.success();
    }

    /**
     * 添加评论
     * @param comments
     * @return
     */

    @PostMapping("/comments")
    public Result addcom(@RequestBody Comments comments){
        log.info("添加评论，内容为：{}",comments);
        articlesService.addcom(comments);
        return Result.success();

    }

    /**
     * 查询评论
     * @param articleId
     * @return
     */
    @GetMapping("/comments/{articleId}")
    public Result selectcom(@PathVariable Integer articleId){
        log.info("查询评论，文章ID为：{}",articleId);
        List<Comments> comments = articlesService.selectcom(articleId);
        return Result.success(comments);

    }
    /**
     * 点赞
     * @param
     * @return
     */
    @PostMapping("/upvotes")
    public Result upvotes(@RequestBody Upvotes upvotes){
        log.info("点赞，文章信息为：{}",upvotes);
        articlesService.upvotes(upvotes);
        return Result.success();
    }
    /**
     * 查询点赞
     * @param
     * @return
     */
    @GetMapping("/upvotes/{articleId}")
    public Result selectupvotes(@PathVariable Integer articleId){
        log.info("查询点赞，文章ID为：{}",articleId);
        List<Upvotes> upvotes = articlesService.selectupvotes(articleId);
        return Result.success(upvotes);
    }
}
